This example reads the value of the "Name", in the current user's registry, under the key "Names".
Dim key As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Names")
Dim name As String = CType(key.GetValue("Name"), String)
Replace the "Names" parameter with the name of a key that exists directly under the HKEY_CURRENT_USER node of the registry.
Replace the "Name" parameter with the name of a value that exists directly under the "Names" node.
The GetValue method returns an Object. If you have Option Strict On in your code, you must cast the return value to
the type of data that you previously put into the value.
GetValue returns Nothing if the value does not exist.
When reading the registry from a Web application, the current user depends on the authentication and impersonation implemented in the Web application. To determine the current user in a Web application, see Code: Getting the User or Account Identity (Visual Basic).
The following conditions may cause an exception:
Registry keys hold data, and all input data should be verified before it is used in an application.
Code:
Deleting a Key from the Registry (Visual Basic) | Code:
Creating a Key In the Registry (Visual Basic) |